/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.interceptors;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts2.StrutsStatics;

/**
 *
 * @author dean
 */
public class ClearCacheInterceptor extends AbstractInterceptor{
    private static final Logger logger = Logger.getLogger(ClearCacheInterceptor.class);
    @Override
    public String intercept(ActionInvocation ai) throws Exception {
        ActionContext context = (ActionContext) ai.getInvocationContext();
        HttpServletResponse response = (HttpServletResponse) context.get(StrutsStatics.HTTP_RESPONSE);
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", 0);
        String result = ai.invoke();
        logger.debug("Cached Cleared.");
        return result;
    }
    
}
